package demo;
import java.util.*;
public class Test {
    static class IntCmp implements Comparator<Integer>{
        @Override
        public int compare(Integer o1, Integer o2) {
            return o2-o1;
        }
    }
    public static void main5(String[] args) {
        PriorityQueue<Integer> Pq = new PriorityQueue<>(new Comparator<Integer>(){
           public int compare(Integer o1,Integer o2){
               return o2-o1;
           }
        });
        int[] array = new int[]{27,15,19,18,28,34,65,49,25,37};
        for(int x:array){
            Pq.offer(x);
        }
        System.out.println(Pq.peek());
    }
    public static void main4(String[] args) {
        PriorityQueue<Integer> pQ = new PriorityQueue<>(new IntCmp());
        pQ.offer(9);
        pQ.offer(0);
        pQ.offer(6);
        pQ.offer(7);
        System.out.println(pQ.peek());
    }
    public static void main3(String[] args) {
        // 创建一个空的优先级队列，底层默认容量是11
        PriorityQueue<Integer> q1 = new PriorityQueue<>();
        // 创建一个空的优先级队列，底层的容量为initialCapacity
        PriorityQueue<Integer> q2 = new PriorityQueue<>(100);//自己就可以设置底层容量
        ArrayList<Integer> list = new ArrayList<>();
        list.add(4);
        list.add(3);
        list.add(2);
        list.add(1);
        // 用ArrayList对象来构造一个优先级队列的对象
        // q3中已经包含4了个元素
        PriorityQueue<Integer> q3 = new PriorityQueue<>(list);
        System.out.println(q3.size());
        System.out.println(q3.peek());
    }
    public static void main2(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(1);
        priorityQueue.offer(4);
        System.out.println(priorityQueue.size());
        priorityQueue.offer(0);
        System.out.println(priorityQueue.peek());
        System.out.println(priorityQueue.poll());
        System.out.println("清空");
        System.out.println(priorityQueue.size());
        priorityQueue.clear();
    }
    public static void main(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        int[] array = new int[]{27,15,19,18,28,34,65,49,25,37};
        TestHeap testHeap = new TestHeap();
        testHeap.createHeap(array);
        testHeap.offer(90);
        testHeap.heapSort();
    }
}
